Public Class OwnLabPrice
    Protected _year As String
    Protected _OwnLabType As New OwnLabType()
    Protected _lab_price As Double
    Protected _Data As ArrayList
    Protected _DataCurrent As Integer

    Public Property year() As String
        Get
            Return _year
        End Get
        Set(ByVal value As String)
            _year = value
        End Set
    End Property

    Public Property OwnLabType() As OwnLabType
        Get
            Return _OwnLabType
        End Get
        Set(ByVal value As OwnLabType)
            _OwnLabType = value
        End Set
    End Property

    Public Property lab_price() As Double
        Get
            Return _lab_price
        End Get
        Set(ByVal value As Double)
            _lab_price = value
        End Set
    End Property

    Public Function getOwnLabPriceDetailByYear(ByVal pYear As String) As System.Data.DataSet
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_OwnLabPriceDetailByYear"

        Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inYear", pYear)
        objCmd.Parameters.Add(objParam)

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "OwnLabPriceDetailByYear")

        Return objDs
    End Function

    Protected Function getsOwnLabPriceDetailByYear(ByVal pYear As String) As ArrayList
        Dim outResult As New ArrayList()
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_OwnLabPriceDetailByYear"

        Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inYear", pYear)
        objCmd.Parameters.Add(objParam)

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "OwnLabPriceDetailByYear")

        For Each objDr As System.Data.DataRow In objDs.Tables("OwnLabPriceDetailByYear").Rows
            Dim obj As OwnLabPrice = New OwnLabPrice()
            obj.year = objDr.Item("year").ToString()
            obj.OwnLabType.own_lab_type_id = objDr.Item("own_lab_type_id").ToString()
            obj.OwnLabType.own_lab_type_name = objDr.Item("own_lab_type_name").ToString()
            obj.lab_price = objDr.Item("lab_price").ToString()
            outResult.Add(obj)
        Next

        Return outResult
    End Function

    Public Function insertOwnLabPrice() As Boolean
        Try
            Dim decryptText As New DateUtilities.Encrypt_Data()
            Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
                decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
                "PoliceHealthConnectionString").ToString(), True))
            Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.StoredProcedure
            objCmd.CommandText = "proc_INSERT_OwnLabPrice"

            Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inYear", year)
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inOwnLabTypeID", OwnLabType.own_lab_type_id)
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inLabPrice", lab_price)
            objCmd.Parameters.Add(objParam)

            objConn.Open()
            objCmd.ExecuteNonQuery()
            objConn.Close()

            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function NextRecord() As Boolean
        If ((Not _Data Is Nothing) AndAlso (((Not _Data Is Nothing) AndAlso _
            (_DataCurrent < _Data.Count And _Data.Count > 0)))) Then
            _year = _Data(_DataCurrent).year
            _OwnLabType.own_lab_type_id = _Data(_DataCurrent).OwnLabType.own_lab_type_id
            _OwnLabType.own_lab_type_name = _Data(_DataCurrent).OwnLabType.own_lab_type_name
            _lab_price = _Data(_DataCurrent).lab_price
            _DataCurrent += 1
            Return True
        End If
        Return False
    End Function

    Public Sub loadOwnLabPriceDetailByYear(ByVal pYear As String)
        _Data = New ArrayList
        _DataCurrent = 0
        _Data = getsOwnLabPriceDetailByYear(pYear)
    End Sub

End Class
